#include<iostream>
#include<vector>

using namespace std;

int n;
vector<int> tree;
vector<int> ans;

void dfs(int index){
	if(index >= n || tree[index]==-1) return;
	ans.push_back(tree[index]);
	int l = index*2+1;
	int r = index*2+2;
	dfs(l);
	dfs(r);
}

int main(){
	cin>>n;
	tree = vector<int>(n);
	for(int i=0;i<n;i++){
		cin>>tree[i];
	}
	
	dfs(0);
	
	for(int i=0;i<ans.size()-1;i++){
		cout<<ans[i]<<" ";
	}
	cout<<ans[ans.size()-1]<<endl;
	
    return 0;
} 
